package com.test.daily.leetcode.y2021.m10.day1017;

import java.util.ArrayList;
import java.util.List;

/**
 * @descriptions:
 * @author: Tom
 * @date: 2021/10/17 下午 10:42
 * @version: 1.0
 */
public class Code01_KthSmallest {
    public static void main(String[] args) {

    }
    public static int kthSmallest(TreeNode root, int k) {
        ArrayList<Integer> list = new ArrayList<>();
        in(root,list);
        return list.get(k-1);
    }
    public static void in(TreeNode root, List<Integer> arr){
        if(root == null){
            return;
        }
        in(root.left, arr);
        arr.add(root.val);
        in(root.right, arr);
    }

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
